package com.yupi.mianshiya.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yupi.mianshiya.constant.CommonConstant;
import com.yupi.mianshiya.model.dto.feedback.feedbackQueryRequest;
import com.yupi.mianshiya.model.entity.Feedback;
import com.yupi.mianshiya.service.FeedbackService;
import com.yupi.mianshiya.mapper.FeedbackMapper;
import com.yupi.mianshiya.utils.SqlUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import java.util.Date;


@Service
public class FeedbackServiceImpl extends ServiceImpl<FeedbackMapper, Feedback>
    implements FeedbackService{

    @Override
    public QueryWrapper<Feedback> getQueryWrapper(feedbackQueryRequest feedbackQueryRequest) {
        QueryWrapper<Feedback> queryWrapper = new QueryWrapper<>();
        if (feedbackQueryRequest == null) {
            return queryWrapper;
        }
        Long id = feedbackQueryRequest.getId();
        Long userId = feedbackQueryRequest.getUserId();
        String status = feedbackQueryRequest.getStatus();
        String content = feedbackQueryRequest.getContent();
        String sortField = feedbackQueryRequest.getSortField();
        String sortOrder = feedbackQueryRequest.getSortOrder();

        // 精确查询
        queryWrapper.eq(ObjectUtils.isNotEmpty(id), "id", id);
        queryWrapper.eq(ObjectUtils.isNotEmpty(userId), "userId", userId);
        queryWrapper.eq(ObjectUtils.isNotEmpty(status), "status", status);


        //模糊
        queryWrapper.like(ObjectUtils.isNotEmpty(content), "content", content);


        // 排序规则
        queryWrapper.orderBy(SqlUtils.validSortField(sortField),
                sortOrder.equals(CommonConstant.SORT_ORDER_ASC),
                sortField);

        return queryWrapper;
    }
}




